<%-- 
    Document   : index
    Created on : 14-nov-2011, 18.34.35
    Author     : Admin
--%>


<%@include file="/include/header.jsp" %>

        <%@page import="data.CommentIO"%>
        <%@page import="business.Comment"%>
        <%@page import="java.io.IOException"%>
        <%
            String message = (String)request.getAttribute("message");
            if(message == null)
                message = "";
            
            Comment comm = (Comment)request.getAttribute("comment");
            if(comm == null)   
                comm = new Comment();
                                 
            //String filePath = getServletContext().getRealPath("/WEB-INF/comments.txt");
            // per esteso:
            ServletContext sc = getServletContext();
            String filePath = sc.getRealPath("/WEB-INF/comments.txt");
            
            String commentsSoFar = "";
            try
            {
                commentsSoFar = CommentIO.read(filePath);
            }
            catch(IOException e)
            {
                message = "Cannot read from file.";
            }
            
        %>
        <h1>Insert comments</h1>
        <table cellspacing="5" cellpadding="5" border="1">
            <tr>
                <td>Comments so far:</td>
            </tr>
            <tr>
                <td><%= commentsSoFar %></td>
            </tr>
        </table>
            <br />
            <p>
                <%= message %>
            </p>
            <form action="submitcomment" method="post">
                <table>
                    <tr>
                        <td align="right">Name:</td>
                        <td><input type="text" name="name" value="<%= comm.getName() %>" /></td>
                    </tr>
                    <tr>
                        <td align="right">Comment:</td>
                        <td><textarea name="comment"><%= comm.getComment() %></textarea></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td><input type="submit" value="submit" /></td>
                    </tr>
                </table>
            </form>

   <%@include file="/include/footer.jsp" %>
